Fundamentos da Engenharia de Prompt
Engenharia de Prompt (EP) é o processo de projetar e otimizar entradas de texto para orientar Modelos de Linguagem de Grande Porte (LLMs) rumo a resultados de alta qualidade e consistência.
1. Definindo a Interface
O que: Serve como a principal interface de "programação" para a IA generativa.
Por quê: Transforma a interação de previsão de texto bruta e imprevisível para a execução intencional e estruturada de instruções.
2. Fundamentos dos Modelos
- Modelos Base LLMs: Treinados simplesmente para prever o próximo token com base em relações estatísticas em grandes conjuntos de dados, maximizando a probabilidade $P(w_t | w_1, w_2, ..., w_{t-1})$.
- Modelos Adaptados por Instruções LLMs: Ajustados por meio de Aprendizado por Reforço com Feedback Humano (RLHF) para seguir explicitamente direções específicas e atuar como assistentes úteis.
3. Anatomia de um Prompt Efetivo
Como: Um prompt sólido geralmente contém:
- Instrução: A ação específica necessária.
- Conteúdo Principal: Os dados-alvo a serem processados.
- Conteúdo Secundário: Parâmetros, formatação ou restrições (para lidar com aleatoriedade e alucinações).
A Realidade da Tokenização
Modelos não leem palavras; eles processam tokens—unidades menores de sequências de texto usadas para calcular probabilidades estatísticas.
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
What is the primary difference between a Base LLM and an Instruction-Tuned LLM?
Question 2
Why is the use of delimiters (like triple backticks or hashes) considered a best practice in prompt engineering?
Challenge: Tutor AI Constraints
Refining prompts for educational safety.
You are building a tutor-style AI for a startup. The model is currently giving away answers too quickly and sometimes making up facts when it doesn't know the answer.
Task 1
Implement "Chain-of-thought" prompting in the system message to prevent the AI from giving away answers immediately.
Solution:
Instruct the model to:
Instruct the model to:
"Work through the problem step-by-step before providing the final answer. Do not reveal the final answer until the student has attempted the steps."Task 2
Apply an "out" to prevent fabrications (hallucinations) when the AI doesn't know the answer.
Solution:
Add the explicit instruction:
Add the explicit instruction:
"If you do not know the answer based on the provided text or standard curriculum, state clearly that you do not know."